﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Galaxy.AutoCAD.Options;

namespace Galaxy.AutoCAD.Windows
{
    public partial class SplitBackStripBothwayLaminateWindows : Form
    {
        public SplitBackStripBothwayLaminateWindows()
        {
            InitializeComponent();
        }

        private void SplitBackStripBothwayLaminateWindows_Load(object sender, EventArgs e)
        {
            this.textBox1.Focus();
            this.textBox1.Text = "6000";
            this.textBox2.Text = "3000";
            this.textBox3.Text = "4";
            this.textBox4.Text = "300";
            this.textBox5.Text = "500";
            this.comboBox1.Items.Add("1");
            this.comboBox1.Items.Add("5");
            this.comboBox1.Items.Add("10");
            this.comboBox1.Items.Add("50");
            this.comboBox1.Items.Add("100");
            if (this.comboBox1.Items.Count > 0)
            {
                if (this.comboBox1.Items.Contains("10"))
                {
                    this.comboBox1.SelectedItem = "10";
                }
                else
                {
                    this.comboBox1.SelectedItem = comboBox1.Items[0];
                }
            }
        }

        private void textBox1_Click(object sender, EventArgs e)
        {
            this.textBox1.SelectAll();
        }

        private void textBox2_Click(object sender, EventArgs e)
        {
            this.textBox2.SelectAll();
        }

        private void textBox3_Click(object sender, EventArgs e)
        {
            this.textBox3.SelectAll();
        }

        private void textBox4_Click(object sender, EventArgs e)
        {
            this.textBox4.SelectAll();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            LaminateOptionTool.SplitBackStripBothwayLaminatePass = "0";
            LaminateOptionTool.LaminateLengthLimitValue = 6000.0;
            LaminateOptionTool.LaminateMaximalWidthLimitValue = 3000.0;
            LaminateOptionTool.LaminateLengthWidthRatioLimitValue = 4.0;
            LaminateOptionTool.LaminateBackStripWidthValue = 300.0;
            LaminateOptionTool.LaminateModuleValue = 10.0;
            LaminateOptionTool.LaminateMinimumWidthLimitValue = 500.0;
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            LaminateOptionTool.SplitBackStripBothwayLaminatePass = "1";
            double laminateLengthLimitValue;
            if (double.TryParse(textBox1.Text, out laminateLengthLimitValue))
            {
                if (laminateLengthLimitValue >= 5000.0 && laminateLengthLimitValue <= 6000.0)
                {
                    LaminateOptionTool.LaminateLengthLimitValue = laminateLengthLimitValue;
                }
                else
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请输入有效值!");
                    textBox1.Focus();
                    return;
                }
            }
            else
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请输入有效值!");
                textBox1.Focus();
                return;
            }
            double laminateMaximumWidthLimitValue;
            if (double.TryParse(textBox2.Text, out laminateMaximumWidthLimitValue))
            {
                if (laminateMaximumWidthLimitValue >= 2500.0 && laminateMaximumWidthLimitValue <= 3000.0)
                {
                    LaminateOptionTool.LaminateMaximalWidthLimitValue = laminateMaximumWidthLimitValue;
                }
                else
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请输入有效值!");
                    textBox2.Focus();
                    return;
                }
            }
            else
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请输入有效值!");
                textBox2.Focus();
                return;
            }
            double laminateLengthWidthRatioLimitValue;
            if (double.TryParse(textBox3.Text, out laminateLengthWidthRatioLimitValue))
            {
                if (laminateLengthWidthRatioLimitValue >= 4.0 && laminateLengthWidthRatioLimitValue <= 5.0)
                {
                    LaminateOptionTool.LaminateLengthWidthRatioLimitValue = laminateLengthWidthRatioLimitValue;
                }
                else
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请输入有效值!");
                    textBox3.Focus();
                    return;
                }
            }
            else
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请输入有效值!");
                textBox3.Focus();
                return;
            }
            double laminateBackStripWidthValue;
            if (double.TryParse(textBox4.Text, out laminateBackStripWidthValue))
            {
                if (laminateBackStripWidthValue >= 200.0 && laminateBackStripWidthValue <= 450.0)
                {
                    LaminateOptionTool.LaminateBackStripWidthValue = laminateBackStripWidthValue;
                }
                else
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请输入有效值!");
                    textBox4.Focus();
                    return;
                }
            }
            else
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请输入有效值!");
                textBox4.Focus();
                return;
            }
            double laminateModuleValue;
            if (comboBox1.SelectedItem == null)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请选择有效值!");
                comboBox1.Focus();
                return;
            }
            else
            {
                if (double.TryParse(comboBox1.Text, out laminateModuleValue))
                {
                    LaminateOptionTool.LaminateModuleValue = laminateModuleValue;
                }
                else
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请选择有效值!");
                    comboBox1.Focus();
                    return;
                }
            }
            double laminateMinimumWidthLimitValue;
            if (double.TryParse(textBox5.Text, out laminateMinimumWidthLimitValue))
            {
                if (laminateMinimumWidthLimitValue >= 400.0 && laminateMinimumWidthLimitValue <= 600.0)
                {
                    LaminateOptionTool.LaminateMinimumWidthLimitValue = laminateMinimumWidthLimitValue;
                }
                else
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请输入有效值!");
                    textBox5.Focus();
                    return;
                }
            }
            else
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请输入有效值!");
                textBox5.Focus();
                return;
            }
            this.Close();
        }

        private void comboBox1_Click(object sender, EventArgs e)
        {
            this.comboBox1.SelectAll();
        }

        private void textBox5_Click(object sender, EventArgs e)
        {
            this.textBox5.SelectAll();
        }
    }
}
